import Router from 'koa-router';
import tokenAuth from '../middleware/tokenAuth';
import componentContainer from '../../components/componentContainer';

const router = new Router({
  prefix: '/api/servers',
});

router.use(tokenAuth());

router.post('/', async (ctx) => {
  const { redis } = ctx;

  const onlineServer = await redis.keys('server:*');
  ctx.body = {
    ok: true,
    onlineServer,
  };
});

router.post('/bps', async (ctx) => {
  const {
    studentId, teacherId, beginAt, endAt, verbose,
  } = ctx.request.body;

  const apiBridge = componentContainer.getApiBridge();

  const response = await apiBridge.getBitRate(teacherId, studentId, beginAt, endAt, verbose);

  ctx.body = {
    ok: true,
    response,
  };
});

export default router;
